#include <iostream>
#include"statement.h"
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	int x;
	while(1)
	{
	cout<<"1 银行模拟"<<endl<<"2 退出"<<endl; 
	cin>>x;
	if(x==1)
	{
		BankSimulation();
		break;
	}
	else if(x==2)
	{
		break;
	}
	else
	{
		cout<<"输入错误，请重新输入"<<endl; 
	}
	}
	return 0;
}



#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<cstdlib>
#include<algorithm> 
#include"statement.h"
using namespace std; 



/* run this program using the console pauser or add your own getch, system("pause") or input loop */



int BankSimulation()
{ 
	int alltime=0;
	int customer=0;
	int business1=0,business2=0,business3=0,business4=0;
	int a,b;
	struct people *first=NULL,*c1;
	struct people *second=NULL,*c2;
	struct people *third=NULL,*c3;
	struct people *fourth=NULL,*c4;
	struct people *c,*d; 
	int w1=0,w2=0,w3=0,w4=0;
	int q1,q2,q3; 
	struct people *y[4];
	int g[10000]; 
	while(1)
	{
	printf("1，系统自动初始化并开始模拟\n");
//	printf("2，手动设置数据实现模拟\n请输入：\n");
	scanf("%d",&a);
	if(a==1)
	{
		first=(struct people*)malloc(sizeof(struct people));
		c=first;
		c->arrivetimeh =8;
		c->arrivetimem =1;
		c->work =1;
		c->id =1;
		while(c->id <=59)
		{
			q1=(rand()%(12-8)+8);
			q2=(rand()%(60-0)+0);
			q3=(rand()%(4-1)+1);
			if(q1!=c->arrivetimeh )
			{
				d=(struct people*)malloc(sizeof(struct people));
				d->arrivetimeh =q1;
				d->arrivetimem =q2;
				d->work =q3;
				d->id =c->id +1;
				d->next =NULL;
				c->next =d;
				c=c->next ;
				printf("%d %d\n",q1 ,q2 );
			}
			else if(q2!=c->arrivetimem )
			{
				d=(struct people*)malloc(sizeof(struct people));
				d->arrivetimeh =q1;
				d->arrivetimem =q2;
				d->work =q3;
				d->id =c->id +1;
				d->next =NULL;
				c->next =d;
				c=c->next ;
				printf("%d %d\n",q1 ,q2 );
			}
		}
		/////下午
		while(c->id <=99)
		{
			q1=(rand()%(18-14)+14);
			q2=(rand()%(60-0)+0);
			q3=(rand()%(4-1)+1);
			if(q1!=c->arrivetimeh )
			{
				d=(struct people*)malloc(sizeof(struct people));
				d->arrivetimeh =q1;
				d->arrivetimem =q2;
				d->work =q3;
				d->id =c->id +1;
				d->next =NULL;
				c->next =d;
				c=c->next ;
		    	printf("%d %d\n",q1 ,q2 );
			}
			else if(q2!=c->arrivetimem )
			{
				d=(struct people*)malloc(sizeof(struct people));
				d->arrivetimeh =q1;
				d->arrivetimem =q2;
				d->work =q3;
				d->id =c->id +1;
				d->next =NULL;
				c->next =d;
				c=c->next ;
				printf("%d %d\n",q1 ,q2 );
			}
		} 
		
		d=first;
		for(int e=0;e<c->id ;e++)
		{
			g[e]=(d->arrivetimeh )*600+(d->arrivetimem)*10 +(d->work );
			d=d->next ;
		}
		sort(g,g+c->id );
//		for(int e=0;e<c->id ;e++)
//		{
//			printf("%d\n",g[e]);
//		}
		d=first;
		for(int e=0;e<c->id ;e++)
		{
			 
			d->arrivetimeh =(g[e]/10)/60;
			d->arrivetimem =(g[e]/10)%60;
			d->work  =g[e]%10;
			d=d->next ;

		}
//		d=first;
//		for(int e=0;e<c->id ;e++)
//		{
//			printf("%d %d\n",d->arrivetimeh ,d->arrivetimem );
//			d=d->next ;
//		}
	
		break; 
	}
	else
	{
		printf("输入错误，请重新输入：");
	}
	} 
	//开始模拟
	c=first;
	///上午 
	for(int i=8;i<12;i++)
	{
		for(int j=0;j<60;j++)
		
		{
						
	
				if(((c->arrivetimeh )*60+c->arrivetimem )<=(i*60+j))
				{
					if(w1==0)
					{
					//	printf("%d\n",(c->arrivetimeh )*60+c->arrivetimem ); 
						w1=window(c->work );
						y[0]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w2==0)
					{
						w2=window(c->work );
						y[1]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w3==0)
					{
						w3=window(c->work );
						y[2]=c;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w4==0)
					{
						w4=window(c->work );
						y[3]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else
					{
						if(w1>0)
						{
						w1--;	
						 } 
						if(w2>0)
						{
						w2--;	
						 } 
						if(w3>0)
						{
						w3--;	
						 } 
						if(w4>0)
						{
						w4--;	
						 } 
						
						
						if(w1==0)
						{
							printf("第%d号顾客再第1号窗口办理完业务\n",y[0]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[0]->arrivetimeh *60+y[0]->arrivetimem ));
							customer++;
						}
						else if(w2==0)
						{
							printf("第%d号顾客再第2号窗口办理完业务\n",y[1]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[1]->arrivetimeh *60+y[1]->arrivetimem ));
							customer++;
						}
						else if(w3==0)
						{
							printf("第%d号顾客再第3号窗口办理完业务\n",y[2]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[2]->arrivetimeh *60+y[2]->arrivetimem ));
							customer++;
						}
						else if(w4==0)
						{
							printf("第%d号顾客再第4号窗口办理完业务\n",y[3]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[3]->arrivetimeh *60+y[3]->arrivetimem ));
							customer++;
						}
						if(c->next ==NULL)
						{
							if(w1+w2+w3+w4==0)
							{
								break;
							}
						}
					}
				}
					 
			else if(i>12)
			{
				break;
			}
		}
		
	 }
	  
	 ////下午 
	
	for(int i=14;i<18;i++)
	{
		for(int j=0;j<60;j++)
		
		{
						
	
				if(((c->arrivetimeh )*60+c->arrivetimem )<=(i*60+j))
				{
					if(w1==0)
					{
					//	printf("%d\n",(c->arrivetimeh )*60+c->arrivetimem ); 
						w1=window(c->work );
						y[0]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w2==0)
					{
						w2=window(c->work );
						y[1]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w3==0)
					{
						w3=window(c->work );
						y[2]=c;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else if(w4==0)
					{
						w4=window(c->work );
						y[3]=c ;
						if(c->next !=NULL)
						{
							c=c->next ;
						}
					}
					else
					{
						if(w1>0)
						{
						w1--;	
						 } 
						if(w2>0)
						{
						w2--;	
						 } 
						if(w3>0)
						{
						w3--;	
						 } 
						if(w4>0)
						{
						w4--;	
						 } 
						
						
						if(w1==0)
						{
							printf("第%d号顾客再第1号窗口办理完业务\n",y[0]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[0]->arrivetimeh *60+y[0]->arrivetimem ));
							customer++;
						}
						else if(w2==0)
						{
							printf("第%d号顾客再第2号窗口办理完业务\n",y[1]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[1]->arrivetimeh *60+y[1]->arrivetimem ));
							customer++;
						}
						else if(w3==0)
						{
							printf("第%d号顾客再第3号窗口办理完业务\n",y[2]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[2]->arrivetimeh *60+y[2]->arrivetimem ));
							customer++;
						}
						else if(w4==0)
						{
							printf("第%d号顾客再第4号窗口办理完业务\n",y[3]->id  );
							if(y[0]->work ==1)
							{
								business1++;
	
							}
							else if(y[0]->work ==2)
							{
								business2++;
							}
							else if(y[0]->work ==3)
							{
								business3++;
							}
							else if(y[0]->work ==4)
							{
								business4++;
							}
							alltime=alltime+((i*60+j)-(y[3]->arrivetimeh *60+y[3]->arrivetimem ));
							customer++;
						}
						if(c->next ==NULL)
						{
							if(w1+w2+w3+w4==0)
							{
								break;
							}
						}
					}
				}
					 
			else if(i>12)
			{
				break;
			}
		}
		
	 }
	 
//	 ////
    printf("\n");
    printf("\n");
	printf("总的逗留时间为%d分钟\n",alltime);
	printf("\n");
    printf("\n");
	printf("客户数为%d\n",customer);
	printf("\n");
    printf("\n");
	printf("办理取款业务人数%d\n",business1);
	printf("\n");
    printf("\n");
	printf("办理存款业务人数%d\n",business2);
	printf("\n");
    printf("\n");
	printf("办理挂失业务人数%d\n",business3);
	printf("\n");
    printf("\n");
	printf("办理还贷业务人数%d\n",business4);
	 
	return 0;
}

int window(int work)
{
	return work*10;
}

int window2(int work)
{
	return work*10;
}

int window3(int work)
{
	return work*10;
}

int window4(int work)
{
	return work*10;
}


int differenth(int q1,struct people *first)//判断随机产生的时针数据不重复 
{
	while(1)
	{
		if(first->arrivetimeh ==q1)
		{
			return 0;
		}
		else
		{
			if(first->next ==NULL)
			{
				return 1;
			}
			else
			{
				first=first->next ;
			}
		}
	}
}


//int differentm(int q2,struct people *first)//判断随机产生的时针数据不重复 
//{
//	while(1)
//	{
//		//if(first->arrivetime==q2)
//		{
//			return 0;
//		}
//		else
//		{
//			if(first->next ==NULL)
//			{
//				return 1;
//			}
//			else
//			{
//				first=first->next ;
//			}
//		}
//	}
//}





struct people{
	int id;
	int arrivetimem;
	int arrivetimeh;
	int work;
	struct people *next;
}; 


int differenth(int q1,struct people *first); 
int differentm(int q2,struct people *first); 
int BankSimulation();
int window(int work);
int window2(int work);
int window3(int work);
int window4(int work);